<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        * {
            margin: 0px;
            padding: 0px;
        }

        #container {
            width: 931px;
            margin: 0px auto;
        }

        #imgButton li {

            width: 230px;
            height: 50px;
            line-height: 50px;
            text-align: center;
            list-style: none;
            border: 1px solid #999;
            float: left;
        }

        #imgButton li.color {
            background-color: #FF6;
        }

        #img li {
            list-style: none;
            display: none;
        }
    </style>
</head>

<body>
    <div id="container">
        <ul id="imgButton">
            <li>美妆推荐</li>
            <li>美妆推荐</li>
            <li>美妆推荐</li>
            <li>美妆推荐</li>
        </ul>
        <ul id="img">
            <li><img src="./素材/tab/0.png" alt=""></li>
            <li><img src="./素材/tab/1.png" alt=""></li>
            <li><img src="./素材/tab/2.png" alt=""></li>
            <li><img src="./素材/tab/3.png" alt=""></li>
        </ul>
    </div>
    <script>
        var buttons = document.getElementById("imgButton").getElementsByTagName("li");
        var imgs = document.getElementById("img").getElementsByTagName("li");
        var last = 0;
        imgs[0].style.display = "block";
        for (var i = 0; i <= 3; i++) {
            buttons[i].index = i;
            buttons[i].onclick = function () {
                buttons[last].classList.remove("color");
                imgs[last].style.display = "none";
                this.classList.add("color");
                imgs[this.index].style.display = "block";
                last = this.index;
            }
        }
    </script>
</body>

</html>